<?php                                                                                                                                                                     
/* -------------------------------------------------------------------------
 * File Name : include.php
 * -------------------------------------------------------------------------                                                                                              
 */

function htmlstart() {
	//Detection du périphérique
	detectmob();
	global $version;
	global $execution_debut;
	$execution = microtime();
	$execution = explode(' ',$execution);
	$execution_debut = $execution[1]+$execution[0];
	?>
    <!DOCTYPE html>
        <html lang="fr">
            <head>
                <!--[if IE]>
                    <meta http-equiv="refresh" content="0; URL=<?=SITE_ROOT?>/front/naverror.php">
                <![endif]-->
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <meta name="description" content="Loterie de Nowel">
                <meta name="author" content="Q&amp;T">
                <meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
                <meta name="apple-mobile-web-app-capable" content="yes" />
                <meta name="apple-mobile-web-app-status-bar-style" content="black" />
                <title>Loterie de Nowel</title>
                <link rel="icon" type="image/png" href="<?=SITE_ROOT?>/pics/favicon.png" />
                <link rel="apple-touch-icon" href="<?=SITE_ROOT?>/pics/favicon.png" />
                <link rel="stylesheet" href="<?=SITE_ROOT?>/css/style.css">
                <link rel="stylesheet" href="<?=SITE_ROOT?>/css/jquery.countdown.css" />
            </head>
            <body onload="setTimeout(function() { window.scrollTo(0, 1) }, 100);">
	<?
}

function loadajax() {
?>
	<!-- JavaScript includes -->
    <script src="<?=SITE_ROOT?>/js/jquery-1.8.2.js"></script>
    <script src="<?=SITE_ROOT?>/js/jquery.countdown.js"></script>
    <script src="<?=SITE_ROOT?>/js/script.js"></script>
    <script src="<?=SITE_ROOT?>/js/funcs.js"></script>
<?
}

function htmlstop() {
	?>
            </body>
        </html>
	<?
}

function check_auth() {
	if ( empty($_SESSION['login'])  )  {
		if ( empty($_COOKIE['cookie_login']) ) {
			$dest = SITE_ROOT."/front/login.php";
			header("Location:$dest");
		}
		else {
        	$_SESSION['login'] = $_COOKIE['cookie_login'];
		}
	}
}

function first_conn() {
	//Ouvre la connexion à la base de donnée
	$db = New Database;
	$sql = "SELECT first_con FROM users WHERE `nom`='".$_SESSION['login']."'";
	$db->select_query($sql);
	$row = $db->retourLigne();
	if ($row['first_con'] == '0') {
        $_SESSION['first_con'] = $row['first_con'];
		$dest = SITE_ROOT."/front/profil.php";
		header("Location:$dest");
	}
}

function divheader() {
	echo '<header>';
		include (SITE_ROOT . '/front/header.php');
	echo '</header>';
}

function divfooter() {
	global $version;
	global $execution_debut;
	global $time;
	$execution = microtime();
	$execution = explode(' ',$execution);
	$execution_fin = $execution[1]+$execution[0];
	$time = $execution_fin-$execution_debut;
	$time = round(($time),3);
	echo '<footer>';
	include (SITE_ROOT . '/front/footer.php');
	echo '</footer>'; 
}

function getuserid() {
	//Ouvre la connexion à la base de donnée
	$db = New Database;

	// Recup id du user
	if (!empty($_COOKIE['cookie_login'])) {
		$sql = "SELECT id FROM users WHERE `nom`='".$_COOKIE['cookie_login']."'";
	}
	else {
		$sql = "SELECT id FROM users WHERE `nom`='".$_SESSION['login']."'";
	}

	$db->select_query($sql);
	$row = $db->retourLigne();
	$_SESSION['user_id'] = $row['id'];
}

function nosection() {
	?>
	<script type="text/javascript">
		$(document).ready(function() {
			$("section").css("display", "none");
			$("section").fadeIn(2000);
		});
	</script>
    <?
}

function smyle($texte) {
	$in=array(
              ' ;)',
              ' :)',
	      ' :-)',
              ' :(',
	      ' :-(',
	      ' :roll:',
              ' :D',
              ' :shame:'
              );
	$out=array(
               ' <img class="smyle" src="../pics/smileys/chris1mwink.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/noel102.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/noel102.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/icon_cry.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/icon_cry.gif" alt="" />',
	       ' <img class="smyle" src="../pics/smileys/noel106.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/noel51.gif" alt="" />',
               ' <img class="smyle" src="../pics/smileys/noel103.gif" alt="" />'
               );
	return str_replace($in,$out,$texte);
}

function detectmob() {
	 if (
		strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')
	 	||
		strstr($_SERVER['HTTP_USER_AGENT'],'iPod')
	 	||
		strstr($_SERVER['HTTP_USER_AGENT'],'android')
		||
		strstr($_SERVER['HTTP_USER_AGENT'],'Android')
                ||
		strstr($_SERVER['HTTP_USER_AGENT'],'blackberry')
		||
		strstr($_SERVER['HTTP_USER_AGENT'],'Windows Phone')
		||
		strstr($_SERVER['HTTP_USER_AGENT'],'symbian')
		||
		strstr($_SERVER['HTTP_USER_AGENT'],'series60')
		||
		strstr($_SERVER['HTTP_USER_AGENT'],'palm')
	)
	{
		$_SESSION['mobile'] = 'mobile';
	}
	else {
		$_SESSION['mobile'] = '';
	}
}
?>
